﻿using Newtonsoft.Json.Linq;
using System;
using System.Data;

namespace LittleBee.Cells
{
	public class CellTypeInfo
	{
		readonly DataRow? _drCellInfo;
		//public CellInfo()
		//{
		//}

		public CellTypeInfo(DataRow drCellInfo, Type constructor)
		{
			_drCellInfo = drCellInfo;
			Constructor = constructor;
		}

		public Int64 ID
		{
			get
			{
				return _drCellInfo!.Field<Int64>("cell_id");
			}
		}
		public string UUID
		{
			get
			{
				return _drCellInfo!.Field<string>("cell_uuid")!;
			}
		}
		public Int64 StoreID
		{
			get
			{
				return _drCellInfo!.Field<Int64>("store_id");
			}
		}
		public string Type
		{
			get
			{
				return _drCellInfo!.Field<string>("type")!;
			}
		}
		public string Name
		{
			get
			{
				return _drCellInfo!.Field<string>("name")!;
			}
		}
		public string Description
		{
			get
			{
				return _drCellInfo!.Field<string>("description")!;
			}
		}
		public string Class
		{
			get
			{
				return _drCellInfo!.Field<string>("class")!;
			}
		}

		public bool Enable
		{
			get
			{
				return _drCellInfo!.Field<bool>("enable");
			}
		}

		public Type Constructor { get; set; }

		public bool IsAttributeOn(string strAttr)
		{
			bool blRet = Attributes.Contains(strAttr);
			return blRet;
		}

		public string CellVersion
		{
			get
			{
				return Revisions.Value<string>("version")!;
			}
		}

		public string ToolVersion
		{
			get
			{
				return Revisions.Value<string>("tool_ver")!;
			}
		}

		public string ServerVersion
		{
			get
			{
				return Revisions.Value<string>("server_ver")!;
			}
		}

		private JArray Attributes
		{
			get
			{
				return JArray.Parse(_drCellInfo!.Field<string>("attributes")!);
			}
		}
		private JObject Helper
		{
			get
			{
				return JObject.Parse(_drCellInfo!.Field<string>("helper")!);
			}
		}
		private JObject Revisions
		{
			get
			{
				return JObject.Parse(_drCellInfo!.Field<string>("Revisions")!);
			}
		}
	}
}
